package com.sh.data.engine.web.webapi.controller.api;

import com.sh.data.engine.application.model.request.api.DataApiAuthApproveOrderRequest;
import com.sh.data.engine.application.model.request.api.DataApiAuthApproveRequest;
import com.sh.data.engine.application.service.api.DataApiAuthApproveApplicationService;
import com.sh.data.engine.domain.annotation.LogExecution;
import com.sh.data.engine.domain.annotation.userlog.Business;
import com.sh.data.engine.domain.annotation.userlog.EngineOperation;
import com.sh.data.engine.domain.api.model.domain.DataApiAuthApproveDomain;
import com.sh.data.engine.domain.api.service.DataApiAuthService;
import com.sh.data.engine.domain.base.model.PageResult;
import com.sh.data.engine.web.webapi.controller.base.response.RestResponseEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author : fuchen
 * @date : 2022/2/10 16:34
 */
@RestController
@RequestMapping("/dataApiAuthApprove")
@Tag(name = "数据服务-授权审批", description = "数据服务-授权审批")
public class DataApiAuthApproveController {

    @Autowired
    private DataApiAuthService dataApiAuthService;

    @Autowired
    private DataApiAuthApproveApplicationService dataApiAuthApproveApplicationService;

    @Operation(summary = "授权审批列表", description = "授权审批列表")
    @GetMapping("/getApiAuthApprovePage")
    public RestResponseEntity<PageResult<DataApiAuthApproveDomain>> getApiAuthApprovePage(
        DataApiAuthApproveRequest dataApiAuthApproveRequest) {
        var result = dataApiAuthApproveApplicationService.getApiAuthApprovePage(dataApiAuthApproveRequest);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "立即审批", description = "立即审批")
    @PostMapping("/approveUserApiAuthById")
    @LogExecution(operation = EngineOperation.DATA_API_APPROVE, business = Business.数据服务)
//    @Log(
//        business = Business.数据服务,
//        operation = Operation.DATA_API_APPROVE)
    public RestResponseEntity<Boolean> approveUserApiAuthById(
        @Valid DataApiAuthApproveOrderRequest dataApiAuthApproveOrderRequest) {
        var result = dataApiAuthApproveApplicationService.approveUserApiAuthById(dataApiAuthApproveOrderRequest);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "取消审批", description = "取消审批")
    @PostMapping("/cancelUserApiAuthById")
    @LogExecution(operation = EngineOperation.DATA_API_CANCEL_APPROVE, business = Business.数据服务)
//    @Log(
//        business = Business.数据服务,
//        operation = Operation.DATA_API_CANCEL_APPROVE)
    public RestResponseEntity<Boolean> cancelUserApiAuthById(
        @Parameter(description = "id", required = true) @RequestParam Long id) {
        var result = dataApiAuthApproveApplicationService.cancelUserApiAuthById(id);
        return RestResponseEntity.success(result);
    }
}
